package cn.fl.institution.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.comm.facade.upload.condition.SysUlFilesRecQueryCondition;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.*;
import cn.fl.capital.constant.CapitalConstant;
import cn.fl.capital.vo.CapFundVO;
import cn.fl.framework.base.constant.WebBaseConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.institution.condition.PrjInsRedmInfoQC;
import cn.fl.institution.condition.PrjInsRedmInterfaceInfoQC;
import cn.fl.institution.constant.PrjInsRedmInfoConstant;
import cn.fl.institution.constant.PrjInsRedmInterfaceInfoConstant;
import cn.fl.institution.dto.PrjInsRedmInfoDTO;
import cn.fl.institution.dto.PrjInsRedmInterfaceInfoDTO;
import cn.fl.institution.service.IPrjInsRedmInfoService;
import cn.fl.institution.service.IPrjInsRedmInterfaceInfoService;
import cn.fl.institution.transform.PrjInsRedmInfoVOTransform;
import cn.fl.institution.transform.PrjInsRedmInterfaceInfoVOTransform;
import cn.fl.institution.vo.PrjDtlInsRedmInfoVO;
import cn.fl.institution.vo.PrjInsRedmInfoVO;
import cn.fl.institution.vo.PrjInsRedmInterfaceInfoVO;
import cn.fl.project.condition.PrjPrdPaySchDQueryCondition;
import cn.fl.project.condition.PrjPrdPaySchMQueryCondition;
import cn.fl.project.constant.PrjPrdPaySchMConstant;
import cn.fl.project.dto.PrjPrdPaySchDDTO;
import cn.fl.project.dto.PrjPrdPaySchMDTO;
import cn.fl.project.service.IPrjPaySchDApiService;
import cn.fl.project.service.IPrjPrdPaySchMApiService;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlFilesRecService;
import com.alibaba.fastjson.JSON;
import fl.flow.facade.flow.dto.FlowStartedDTO;
import fl.ref.fribaseinfo.condition.BankAccInfoQueryCondition;
import fl.ref.fribaseinfo.condition.FriBaseInfoQueryCondition;
import fl.ref.fribaseinfo.constant.FriBaseInfoConstant;
import fl.ref.fribaseinfo.dto.BankAccInfoDTO;
import fl.ref.fribaseinfo.service.IBankAccInfoApiService;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 资管项目赎回表 控制层
 */
@Controller
@RequestMapping("/institution/prjinsredminfo")
public class PrjInsRedmInfoController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(PrjInsRedmInfoController.class);

    /**
     * PrjInsRedmInfo 服务层BEAN
     */
    @Autowired
    private IPrjInsRedmInfoService prjInsRedmInfoService;
    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;
    @Autowired
    private ISysUlFilesRecService sysUlFilesRecService;
    @Autowired
    private IFriBaseInfoService friBaseInfoService;
    @Autowired
    private IPrjPaySchDApiService prjPaySchDApiService;

    @Autowired
    private IPrjInsRedmInterfaceInfoService prjInsRedmInterfaceInfoService;

    @Autowired
    private IPrjPrdPaySchMApiService prjPrdPaySchMApiService;

    @Autowired
    private IBankAccInfoApiService bankAccInfoApiService;




    /**
     * 到列表页面
     */
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载列表页面").setLogOperType(LogOperEnum.REQ).setKeys("toListPage",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView view = new ModelAndView("fl/institution/prjInsRedmInfo/prjInsRedmInfoList");
        return view;
    }

    /**
     * 到申请赎回表页面
     */
    @RequestMapping(value = "/toAssetsListPage.do", method = {RequestMethod.GET})
    public ModelAndView toAssetsListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载资管资产赎回申请列表页面").setLogOperType(LogOperEnum.REQ).setKeys("toAssetsListPage",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()+"roleID="+CurrentThreadContext.getCurrentRoleId()).info();
        ModelAndView view = new ModelAndView("institution/redm/insAssetListPage");
        FriBaseInfoQueryCondition friBaseInfoQueryCondition = new FriBaseInfoQueryCondition();
        friBaseInfoQueryCondition.setInsSts(FriBaseInfoConstant.FRI_BASE_INFO_INS_STS_PASS);
        friBaseInfoQueryCondition.setInsUseCd("2");
        friBaseInfoQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());
        friBaseInfoQueryCondition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        List<FriBaseInfoVO> insCdList = this.friBaseInfoService.searchList(friBaseInfoQueryCondition);
        List<KeyValueVO> bussinessLineDicList = this.sysDictionaryApiService.getKvList(FriBaseInfoConstant.FUND_BUSSINESS_LINE,WebBaseConstant.SYS_SYS_CD,WebBaseConstant.SYS_P_ORG_CD);
        BaseLogUtils.newLogger("查询业务线集合结束").setLogOperType(LogOperEnum.REQ).setKeys("toAssetsListPage","bussinessLineDicList="+ JSON.toJSONString(bussinessLineDicList)).info();
        String fundRasInsNm = null;
        if (CollectionUtils.isNotEmpty(insCdList) && CollectionUtils.isNotEmpty(bussinessLineDicList)) {
            for (FriBaseInfoVO friBaseInfoVO : insCdList) {
                if (StringUtils.isNotEmpty(friBaseInfoVO.getBussinessLine())) {
                    for (KeyValueVO bussinessLineDicVO : bussinessLineDicList) {
                        if (StringUtils.isNotEmpty(bussinessLineDicVO.getKey()) &&
                                friBaseInfoVO.getBussinessLine().equals(bussinessLineDicVO.getKey())) {
                            fundRasInsNm = friBaseInfoVO.getFundRasInsNm();
                            friBaseInfoVO.setFundRasInsNm(fundRasInsNm + "(" + bussinessLineDicVO.getValue() + ")");
                            break;
                        }
                    }
                }

            }
        }
        List<KeyValueVO> redmStsCdList = this.sysDictionaryApiService.getKvList(PrjInsRedmInfoConstant.SYS_DIS_CODE_REDM_002, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
        //回购主体
        List<KeyValueVO> suretySubjectCodeList = this.sysDictionaryApiService.getKvList(FriBaseInfoConstant.FUND_REPORT_ZT, WebBaseConstant.SYS_SYS_CD,WebBaseConstant.SYS_P_ORG_CD);
        view.addObject("insCdList", insCdList);
        view.addObject("redmStsCdList", redmStsCdList);
        view.addObject("suretySubjectCodeList", suretySubjectCodeList);

        return view;
    }

    /**
     * 资管资产赎回记录列表页面
     */
    @RequestMapping(value = "/toAssetRedmsListPage.do", method = {RequestMethod.GET})
    public ModelAndView toAssetRedmsListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载列表页面").setLogOperType(LogOperEnum.REQ).setKeys("toAssetRedmsListPage",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView view = new ModelAndView("institution/redm/insRedmListPage");
        FriBaseInfoQueryCondition qc = new FriBaseInfoQueryCondition();
        qc.setInsSts(FriBaseInfoConstant.FRI_BASE_INFO_INS_STS_PASS);
        qc.setInsUseCd("2");
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
        qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        List<FriBaseInfoVO> insCdList = this.friBaseInfoService.searchList(qc);
        List<KeyValueVO> bussinessLineDicList = this.sysDictionaryApiService.getKvList(FriBaseInfoConstant.FUND_BUSSINESS_LINE,WebBaseConstant.SYS_SYS_CD,WebBaseConstant.SYS_P_ORG_CD);
        BaseLogUtils.newLogger("查询业务线集合结束").setLogOperType(LogOperEnum.REQ).setKeys("toAssetsListPage","bussinessLineDicList="+ JSON.toJSONString(bussinessLineDicList)).info();
        String fundRasInsNm = null;
        if (CollectionUtils.isNotEmpty(insCdList) && CollectionUtils.isNotEmpty(bussinessLineDicList)) {
            for (FriBaseInfoVO friBaseInfoVO : insCdList) {
                if (StringUtils.isNotEmpty(friBaseInfoVO.getBussinessLine())) {
                    for (KeyValueVO bussinessLineDicVO : bussinessLineDicList) {
                        if (StringUtils.isNotEmpty(bussinessLineDicVO.getKey()) &&
                                friBaseInfoVO.getBussinessLine().equals(bussinessLineDicVO.getKey())) {
                            fundRasInsNm = friBaseInfoVO.getFundRasInsNm();
                            friBaseInfoVO.setFundRasInsNm(fundRasInsNm + "(" + bussinessLineDicVO.getValue() + ")");
                            break;
                        }
                    }
                }

            }
        }
        //回购主体
        List<KeyValueVO> suretySubjectCodeList = this.sysDictionaryApiService.getKvList(FriBaseInfoConstant.FUND_REPORT_ZT, WebBaseConstant.SYS_SYS_CD,WebBaseConstant.SYS_P_ORG_CD);
        view.addObject("insCdList", insCdList);
        view.addObject("suretySubjectCodeList", suretySubjectCodeList);
        return view;
    }


    /**
     * 初始化资管资产赎回列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initAssetsList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initAssetsList(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载列表页面").setLogOperType(LogOperEnum.REQ).setKeys("initAssetsList",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String lsCntNo = request.getParameter("lsCntNo");
        String cstNm = request.getParameter("cstNm");
        String insCode = request.getParameter("insCode");
        String redmStatus = request.getParameter("redmStatus");
        String suretySubjectCode = request.getParameter("suretySubjectCode");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        PrjInsRedmInfoQC qc = new PrjInsRedmInfoQC();
        if (StringUtils.isNotEmpty(lsCntNo)) {
            qc.setLsCntNo(lsCntNo);
        }
        if (StringUtils.isNotEmpty(cstNm)) {
            qc.setCstNm(cstNm);
        }
        if (StringUtils.isNotEmpty(insCode)) {
            qc.setInsCode(insCode);
        }
        if (StringUtils.isNotEmpty(redmStatus)) {
            qc.setRedmStatus(redmStatus);
        }
        if (StringUtils.isNotEmpty(suretySubjectCode)) {
            qc.setSuretySubjectCode(suretySubjectCode);
        }
        if(StringUtils.isNotEmpty(CurrentThreadContext.getCurrentRoleId())
                && PrjInsRedmInfoConstant.REDM_CST_MGR_ROLE_ID.equals(CurrentThreadContext.getCurrentRoleId())){
            /**
             * 客户经理需要加入数据权限
             */
            qc.setCstMgrId(CurrentThreadContext.getCurrentUserId());
        }
        page.setCondition(qc);
        Pager pager = this.prjInsRedmInfoService.searchAssetsListPage(page);
        List<PrjInsRedmInfoVO> list = (List<PrjInsRedmInfoVO>) pager.getResultList();
        if(CollectionUtils.isNotEmpty(list)){
            List<KeyValueVO> bussinessLineDicList = this.sysDictionaryApiService.getKvList(FriBaseInfoConstant.FUND_BUSSINESS_LINE,WebBaseConstant.SYS_SYS_CD,WebBaseConstant.SYS_P_ORG_CD);
            BaseLogUtils.newLogger("查询业务线集合结束").setLogOperType(LogOperEnum.REQ).setKeys("toAssetsListPage","bussinessLineDicList="+ JSON.toJSONString(bussinessLineDicList)).info();
            List<KeyValueVO> suretySubjectCodeList = this.sysDictionaryApiService.getKvList(FriBaseInfoConstant.FUND_REPORT_ZT, WebBaseConstant.SYS_SYS_CD,WebBaseConstant.SYS_P_ORG_CD);
            BaseLogUtils.newLogger("查询回购主体配置结束").setLogOperType(LogOperEnum.REQ).setKeys("toAssetsListPage","suretySubjectCodeList="+ JSON.toJSONString(suretySubjectCodeList)).info();
            String fundRasInsNm = null;
            if (CollectionUtils.isNotEmpty(bussinessLineDicList)) {
                for (PrjInsRedmInfoVO prjInsRedmInfoVO : list) {
                    if (StringUtils.isNotEmpty(prjInsRedmInfoVO.getBussinessLine())) {
                        for (KeyValueVO bussinessLineDicVO : bussinessLineDicList) {
                            if (StringUtils.isNotEmpty(bussinessLineDicVO.getKey()) &&
                                    prjInsRedmInfoVO.getBussinessLine().equals(bussinessLineDicVO.getKey())) {
                                fundRasInsNm = prjInsRedmInfoVO.getFundRasInsNm();
                                prjInsRedmInfoVO.setFundRasInsNm(fundRasInsNm + "(" + bussinessLineDicVO.getValue() + ")");
                                break;
                            }
                        }
                    }

                }
            }
            if (CollectionUtils.isNotEmpty(suretySubjectCodeList)){
                for (PrjInsRedmInfoVO prjInsRedmInfoVO : list){
                    if(StringUtils.isNotEmpty(prjInsRedmInfoVO.getSuretySubjectCode())){
                        for(KeyValueVO keyValueVO : suretySubjectCodeList){
                            if(prjInsRedmInfoVO.getSuretySubjectCode().equals(keyValueVO.getKey())){
                                prjInsRedmInfoVO.setSuretySubjectNm(keyValueVO.getValue());
                                break;
                            }
                        }
                    }
                }
            }
        }

        ListPageVO<PrjInsRedmInfoVO> listPage = new ListPageVO<PrjInsRedmInfoVO>(list, pager.getTotalCount());
        return listPage;
    }

    /**
     * 初始化赎回记录列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initAssetsRedmList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initAssetsRedmList(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载列表页面").setLogOperType(LogOperEnum.REQ).setKeys("initAssetsRedmList",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String lsCntNo = request.getParameter("lsCntNo");
        String crCntNo = request.getParameter("crCntNo");
        String cstNm = request.getParameter("cstNm");
        String insCode = request.getParameter("insCode");
        String suretySubjectCode = request.getParameter("suretySubjectCode");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }
        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }
        PrjInsRedmInfoQC qc = new PrjInsRedmInfoQC();
        if (StringUtils.isNotEmpty(lsCntNo)) {
            qc.setLsCntNo(lsCntNo);
        }
        if (StringUtils.isNotEmpty(crCntNo)) {
            qc.setCrCntNo(crCntNo);
        }
        if (StringUtils.isNotEmpty(cstNm)) {
            qc.setCstNm(cstNm);
        }
        if (StringUtils.isNotEmpty(insCode)) {
            qc.setInsCode(insCode);
        }
        if (StringUtils.isNotEmpty(suretySubjectCode)) {
            qc.setSuretySubjectCode(suretySubjectCode);
        }
        if(StringUtils.isNotEmpty(CurrentThreadContext.getCurrentRoleId())
            && PrjInsRedmInfoConstant.REDM_CST_MGR_ROLE_ID.equals(CurrentThreadContext.getCurrentRoleId())){
            /**
             * 客户经理需要加入数据权限
             */
            qc.setCstMgrId(CurrentThreadContext.getCurrentUserId());
        }
        page.setCondition(qc);
        Pager pager = this.prjInsRedmInfoService.searchAssetsRedmListPage(page);
        List<PrjInsRedmInfoVO> list = (List<PrjInsRedmInfoVO>) pager.getResultList();
        if(CollectionUtils.isNotEmpty(list)){
            List<KeyValueVO> bussinessLineDicList = this.sysDictionaryApiService.getKvList(FriBaseInfoConstant.FUND_BUSSINESS_LINE,WebBaseConstant.SYS_SYS_CD,WebBaseConstant.SYS_P_ORG_CD);
            BaseLogUtils.newLogger("查询业务线集合结束").setLogOperType(LogOperEnum.REQ).setKeys("toAssetsListPage","bussinessLineDicList="+ JSON.toJSONString(bussinessLineDicList)).info();
            List<KeyValueVO> suretySubjectCodeList = this.sysDictionaryApiService.getKvList(FriBaseInfoConstant.FUND_REPORT_ZT, WebBaseConstant.SYS_SYS_CD,WebBaseConstant.SYS_P_ORG_CD);
            BaseLogUtils.newLogger("查询回购主体配置结束").setLogOperType(LogOperEnum.REQ).setKeys("toAssetsListPage","suretySubjectCodeList="+ JSON.toJSONString(suretySubjectCodeList)).info();
            String fundRasInsNm = null;
            if (CollectionUtils.isNotEmpty(bussinessLineDicList)) {
                for (PrjInsRedmInfoVO prjInsRedmInfoVO : list) {
                    if (StringUtils.isNotEmpty(prjInsRedmInfoVO.getBussinessLine())) {
                        for (KeyValueVO bussinessLineDicVO : bussinessLineDicList) {
                            if (StringUtils.isNotEmpty(bussinessLineDicVO.getKey()) &&
                                    prjInsRedmInfoVO.getBussinessLine().equals(bussinessLineDicVO.getKey())) {
                                fundRasInsNm = prjInsRedmInfoVO.getFundRasInsNm();
                                prjInsRedmInfoVO.setFundRasInsNm(fundRasInsNm + "(" + bussinessLineDicVO.getValue() + ")");
                                break;
                            }
                        }
                    }

                }
            }
            if (CollectionUtils.isNotEmpty(suretySubjectCodeList)){
                for (PrjInsRedmInfoVO prjInsRedmInfoVO : list){
                    if(StringUtils.isNotEmpty(prjInsRedmInfoVO.getSuretySubjectCode())){
                        for(KeyValueVO keyValueVO : suretySubjectCodeList){
                            if(prjInsRedmInfoVO.getSuretySubjectCode().equals(keyValueVO.getKey())){
                                prjInsRedmInfoVO.setSuretySubjectNm(keyValueVO.getValue());
                                break;
                            }
                        }
                    }
                }
            }
        }
        ListPageVO<PrjInsRedmInfoVO> listPage = new ListPageVO<PrjInsRedmInfoVO>(list, pager.getTotalCount());
        return listPage;
    }

    /**
     * 查询资管资产赎回申请信息
     */
    @RequestMapping(value = "/toRedmApplyInfoPage.do", method = {
            RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toRedmApplyInfoPage(HttpServletRequest request,
                                            HttpServletResponse response) {
        BaseLogUtils.newLogger("加载资管资产赎回申请页面").setLogOperType(LogOperEnum.REQ).setKeys("toRedmApplyInfoPage",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        String viewName = "institution/redm/initRedmApplyInfoPage";
        /**
         * 根据角色跳转到不同的赎回申请页面
         */
        if(PrjInsRedmInfoConstant.REDM_CST_MGR_ROLE_ID.equals(CurrentThreadContext.getCurrentRoleId())){
            //客户经理发起赎回
            viewName = "institution/redm/customerManagerRedmApplyInfoPage";
        }

        ModelAndView view = new ModelAndView(viewName);
        String prjId = request.getParameter("prjId");
        PrjInsRedmInfoQC qc = new PrjInsRedmInfoQC();
        if (StringUtils.isEmpty(prjId)) {
            BaseLogUtils.newLogger("请求参数项目id不能为空").setLogOperType(LogOperEnum.REQ).setKeys("toRedmApplyInfoPage",prjId,CurrentThreadContext.getCurrentUserName()).info();
            return view;
        }
        qc.setPrjId(Long.valueOf(prjId));
        PrjInsRedmInfoVO redmApplyInfo = this.prjInsRedmInfoService.searchAssetsRedmApplyInfo(qc);
        BaseLogUtils.newLogger("资管赎回,查询赎回信息结束").setLogOperType(LogOperEnum.REQ).setKeys("toRedmApplyInfoPage","redmApplyInfo="+ JSON.toJSONString(redmApplyInfo),"viewName="+viewName,CurrentThreadContext.getCurrentUserName()).info();
        /**
         * 配置项 是否展示资方接口赎回信息
         */
        int isShowInsRedmInterfaceInfo = this.prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(redmApplyInfo.getInsCode(),PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C041);
        BaseLogUtils.newLogger("资管赎回,查询资方接口赎回信息配置结束").setLogOperType(LogOperEnum.REQ).setKeys("toRedmApplyInfoPage","isShowInsRedmInterfaceInfo="+ isShowInsRedmInterfaceInfo,CurrentThreadContext.getCurrentUserName()).info();

        /**
         * 配置项 回购主体
         */
        List<KeyValueVO> suretySubjectCodeList = this.prjInsRedmInterfaceInfoService.getSuretySubjectCodeList(redmApplyInfo.getInsCode());
        BaseLogUtils.newLogger("资管赎回,查询回购主体信息配置结束").setLogOperType(LogOperEnum.REQ).setKeys("toRedmApplyInfoPage","suretySubjectCodeList="+ JSON.toJSONString(suretySubjectCodeList),CurrentThreadContext.getCurrentUserName()).info();

        /**
         * 配置项 机构是否需要核销逾期才能试算
         */
        int isChargeOffOvd = 0;
        if(BaseConstant.IS_YESNO_YES == redmApplyInfo.getIsOverdue()){
            isChargeOffOvd = this.prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(redmApplyInfo.getInsCode(),PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C042);
        }
        BaseLogUtils.newLogger("资管赎回,查询机构逾期核销配置结束").setLogOperType(LogOperEnum.REQ).setKeys("toRedmApplyInfoPage","isChargeOffOvd="+ isChargeOffOvd,CurrentThreadContext.getCurrentUserName()).info();

        /**
         * 配置项 付款方式
         */
        int repayMode = this.prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(redmApplyInfo.getInsCode(),PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C044);
        BaseLogUtils.newLogger("资管赎回,查询付款方式信息配置结束").setLogOperType(LogOperEnum.REQ).setKeys("toRedmApplyInfoPage","repayMode="+ repayMode,CurrentThreadContext.getCurrentUserName()).info();

        /**
         * 配置项 我司赎回付款账户
         */
        BankAccInfoQueryCondition bankAccInfoQueryCondition = new BankAccInfoQueryCondition();
        bankAccInfoQueryCondition.setFundRasInsId(redmApplyInfo.getFundRasInsId());
        bankAccInfoQueryCondition.setAccTypCd(PrjInsRedmInfoConstant.WS_REDM_PAYMENT_ACCOUNT);
        List<BankAccInfoDTO> redmPaymentAccountDtoList = bankAccInfoApiService.searchList(bankAccInfoQueryCondition);
        BaseLogUtils.newLogger("资管赎回,查询我司赎回付款账户配置结束").setLogOperType(LogOperEnum.REQ).setKeys("toRedmApplyInfoPage","redmPaymentAccountDtoList="+ JSON.toJSONString(redmPaymentAccountDtoList),CurrentThreadContext.getCurrentUserName()).info();
        /**
         * 配置项 资方赎回收款账户
         */
        bankAccInfoQueryCondition.setAccTypCd(PrjInsRedmInfoConstant.ZF_REDM_PAYEE_ACCOUNT);
        List<BankAccInfoDTO> redmPayeeAccountDtoList = bankAccInfoApiService.searchList(bankAccInfoQueryCondition);
        BaseLogUtils.newLogger("资管赎回,查询资方赎回收款账户配置结束").setLogOperType(LogOperEnum.REQ).setKeys("toRedmApplyInfoPage","redmPayeeAccountDtoList="+ JSON.toJSONString(redmPayeeAccountDtoList),CurrentThreadContext.getCurrentUserName()).info();

        view.addObject("redm", redmApplyInfo);
        view.addObject("repayMode", repayMode);
        view.addObject("isChargeOffOvd", isChargeOffOvd);
        view.addObject("suretySubjectCodeList", suretySubjectCodeList);
        view.addObject("redmPayeeAccountDtoList", redmPayeeAccountDtoList);
        view.addObject("redmPaymentAccountDtoList", redmPaymentAccountDtoList);
        view.addObject("isShowInsRedmInterfaceInfo", isShowInsRedmInterfaceInfo);
        return view;
    }

    /**
     * 查询资管资产赎回申请信息
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initAssetsRedmApplyInfo.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initAssetsRedmApplyInfo(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载资管资产赎回申请信息页面").setLogOperType(LogOperEnum.REQ).setKeys("initAssetsRedmApplyInfo",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        String prjId = request.getParameter("prjId");
        PrjInsRedmInfoQC qc = new PrjInsRedmInfoQC();
        if (StringUtils.isEmpty(prjId)) {
            BaseLogUtils.newLogger("请求参数项目prjId不能为空").setLogOperType(LogOperEnum.REQ).setKeys("initAssetsRedmApplyInfo",prjId,CurrentThreadContext.getCurrentUserName()).info();
            return null;
        }
        qc.setPrjId(Long.valueOf(prjId));
        PrjInsRedmInfoVO redmApplyInfo = this.prjInsRedmInfoService.searchAssetsRedmApplyInfo(qc);
        return redmApplyInfo;
    }


    /**
     * 资管赎回详情页面(附加页面)
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/toCustomerManagerRedmInfoPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toCustomerManagerRedmInfoPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("资管赎回详情页面").setLogOperType(LogOperEnum.REQ).setKeys("toCustomerManagerRedmInfoPage",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView view = new ModelAndView("institution/redm/customerManagerRedmInfoPage");
        String id = request.getParameter("redmId");
        PrjInsRedmInfoQC qc = new PrjInsRedmInfoQC();
        if (StringUtils.isEmpty(id)) {
            BaseLogUtils.newLogger("请求参数id不能为空").setLogOperType(LogOperEnum.REQ).setKeys("toCustomerManagerRedmInfoPage",id,CurrentThreadContext.getCurrentUserName()).info();
            return view;
        }
        qc.setId(Long.valueOf(id));
        PrjInsRedmInfoVO redmApplyInfo = this.prjInsRedmInfoService.searchAssetsRedmInfo(qc);
        /**
         * 配置项 是否展示资方接口赎回信息
         */
        int isShowInsRedmInterfaceInfo = this.prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(redmApplyInfo.getInsCode(),PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C041);
        /**
         * 配置项 回购主体
         */
        List<KeyValueVO> suretySubjectCodeList = this.prjInsRedmInterfaceInfoService.getSuretySubjectCodeList(redmApplyInfo.getInsCode());

        /**
         * 配置项 付款方式
         */
        int repayMode = this.prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(redmApplyInfo.getInsCode(),PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C044);
        /**
         * 配置项 我司赎回付款账户
         */
        BankAccInfoQueryCondition bankAccInfoQueryCondition = new BankAccInfoQueryCondition();
        if(null != redmApplyInfo.getRedmPaymentAccountNum()){
            bankAccInfoQueryCondition.setAccTypCd(PrjInsRedmInfoConstant.WS_REDM_PAYMENT_ACCOUNT);
            bankAccInfoQueryCondition.setAccNum(String.valueOf(redmApplyInfo.getRedmPayeeAccountNum()));
            List<BankAccInfoDTO> redmPaymentAccountDtoList = bankAccInfoApiService.searchList(bankAccInfoQueryCondition);
            if(CollectionUtils.isNotEmpty(redmPaymentAccountDtoList)){
                view.addObject("redmPaymentAccount", redmPaymentAccountDtoList.get(0));
            }else{
                view.addObject("redmPaymentAccount", null);
            }
        }
        /**
         * 配置项 资方赎回收款账户
         */
        if(null != redmApplyInfo.getRedmPayeeAccountNum()){
            bankAccInfoQueryCondition.setAccTypCd(PrjInsRedmInfoConstant.ZF_REDM_PAYEE_ACCOUNT);
            bankAccInfoQueryCondition.setAccNum(String.valueOf(redmApplyInfo.getRedmPayeeAccountNum()));
            List<BankAccInfoDTO> redmPayeeAccountDtoList = bankAccInfoApiService.searchList(bankAccInfoQueryCondition);
            if(CollectionUtils.isNotEmpty(redmPayeeAccountDtoList)){
                view.addObject("redmPayeeAccount", redmPayeeAccountDtoList.get(0));
            }else{
                view.addObject("redmPayeeAccount", null);
            }
        }
        //处理suretySubjectNm 融担主体名称数据
        if(StringUtils.isNotEmpty(redmApplyInfo.getSuretySubjectCode())){
            for(KeyValueVO keyValueVO : suretySubjectCodeList){
                if(redmApplyInfo.getSuretySubjectCode().equals(keyValueVO.getKey())){
                    redmApplyInfo.setSuretySubjectNm(keyValueVO.getValue());
                    break;
                }
            }
        }
        /**
         * 赎回原因
         */
        List<KeyValueVO> insRedmResonCodeList = this.sysDictionaryApiService.getKvList(PrjInsRedmInfoConstant.SYS_DIS_CODE_REDM_008, CapitalConstant.SYSCD, CapitalConstant.SYSORG);
        for(KeyValueVO vo : insRedmResonCodeList){
            if(vo.getKey().equals(redmApplyInfo.getInsRedmResonCode())){
                redmApplyInfo.setInsRedmResonNm(vo.getValue());
            }
        }
        /**
         * 具体原因
         */
        List<SysDictionaryDTO> insRedmDetailResonCodeList = this.sysDictionaryApiService.searchChild(CapitalConstant.SYSCD, CapitalConstant.SYSORG, PrjInsRedmInfoConstant.SYS_DIS_CODE_REDM_009, redmApplyInfo.getInsRedmResonCode());
        for(SysDictionaryDTO sysDictionaryDTO : insRedmDetailResonCodeList) {
            if(sysDictionaryDTO.getCode().equals(redmApplyInfo.getInsRedmDetailResonCode())){
                redmApplyInfo.setInsRedmDetailResonNm(sysDictionaryDTO.getCodeNm());
            }
        }
        BaseLogUtils.newLogger("资管赎回详情页面,查询赎回信息结束").setLogOperType(LogOperEnum.REQ).setKeys("toCustomerManagerRedmInfoPage","redmApplyInfo="+ JSON.toJSONString(redmApplyInfo),this.getRequestParameter(request)).info();
        view.addObject("redm", redmApplyInfo);
        view.addObject("repayMode", repayMode);
        view.addObject("suretySubjectCodeList", suretySubjectCodeList);
        view.addObject("isShowInsRedmInterfaceInfo", isShowInsRedmInterfaceInfo);
        view.addObject("pkId", id);
        view.addObject("tabNm", PrjInsRedmInfoConstant.RedmFile.FILE_DEDU_PROVE_TAB_NM);
        return view;
    }

    /**
     * 资管赎回详情页面(省总附加页面)
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/toRedmInfoPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toRedmInfoPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("资管赎回详情页面").setLogOperType(LogOperEnum.REQ).setKeys("toRedmInfoPage",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView view = new ModelAndView("institution/redm/redmInfoPage");
        String id = request.getParameter("redmId");
        PrjInsRedmInfoQC qc = new PrjInsRedmInfoQC();
        if (StringUtils.isEmpty(id)) {
            BaseLogUtils.newLogger("请求参数id不能为空").setLogOperType(LogOperEnum.REQ).setKeys("toRedmInfoPage",id,CurrentThreadContext.getCurrentUserName()).info();
            return view;
        }
        qc.setId(Long.valueOf(id));
        PrjInsRedmInfoVO redmApplyInfo = this.prjInsRedmInfoService.searchAssetsRedmInfo(qc);
        BaseLogUtils.newLogger("资管赎回详情页面,查询资管赎回信息结束!").setKeys("toRedmInfoPage","redmApplyInfo="+JSON.toJSONString(redmApplyInfo)).info();
        /**
         * 配置项 是否展示资方接口赎回信息
         */
        int isShowInsRedmInterfaceInfo = this.prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(redmApplyInfo.getInsCode(),PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C041);
        /**
         * 配置项 回购主体
         */
        List<KeyValueVO> suretySubjectCodeList = this.prjInsRedmInterfaceInfoService.getSuretySubjectCodeList(redmApplyInfo.getInsCode());

        /**
         * 配置项 付款方式
         */
        int repayMode = this.prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(redmApplyInfo.getInsCode(),PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C044);
        /**
         * 配置项 我司赎回付款账户
         */
        BankAccInfoQueryCondition bankAccInfoQueryCondition = new BankAccInfoQueryCondition();
        if(null != redmApplyInfo.getRedmPaymentAccountNum()){
            bankAccInfoQueryCondition.setAccTypCd(PrjInsRedmInfoConstant.WS_REDM_PAYMENT_ACCOUNT);
            bankAccInfoQueryCondition.setAccNum(String.valueOf(redmApplyInfo.getRedmPaymentAccountNum()));
            List<BankAccInfoDTO> redmPaymentAccountDtoList = bankAccInfoApiService.searchList(bankAccInfoQueryCondition);
            BaseLogUtils.newLogger("资管赎回详情页面,查询我司赎回付款账户结束!").setKeys("toRedmInfoPage","redmPaymentAccountDtoList="+ JSON.toJSONString(redmPaymentAccountDtoList),"bankAccInfoQueryCondition="+JSON.toJSONString(bankAccInfoQueryCondition)).info();
            if(CollectionUtils.isNotEmpty(redmPaymentAccountDtoList)){
                view.addObject("redmPaymentAccount", redmPaymentAccountDtoList.get(0));
            }else{
                view.addObject("redmPaymentAccount", null);
            }
        }
        /**
         * 配置项 资方赎回收款账户
         */
        if(null != redmApplyInfo.getRedmPayeeAccountNum()){
            bankAccInfoQueryCondition.setAccTypCd(PrjInsRedmInfoConstant.ZF_REDM_PAYEE_ACCOUNT);
            bankAccInfoQueryCondition.setAccNum(String.valueOf(redmApplyInfo.getRedmPayeeAccountNum()));
            List<BankAccInfoDTO> redmPayeeAccountDtoList = bankAccInfoApiService.searchList(bankAccInfoQueryCondition);
            BaseLogUtils.newLogger("资管赎回详情页面,查询资方赎回收款账户结束!").setKeys("toRedmInfoPage","redmPayeeAccountDtoList="+ JSON.toJSONString(redmPayeeAccountDtoList),"bankAccInfoQueryCondition="+JSON.toJSONString(bankAccInfoQueryCondition)).info();
            if(CollectionUtils.isNotEmpty(redmPayeeAccountDtoList)){
                view.addObject("redmPayeeAccount", redmPayeeAccountDtoList.get(0));
            }else{
                view.addObject("redmPayeeAccount", null);
            }
        }
        //处理suretySubjectNm 融担主体名称数据
        if(StringUtils.isNotEmpty(redmApplyInfo.getSuretySubjectCode())){
            for(KeyValueVO keyValueVO : suretySubjectCodeList){
                if(redmApplyInfo.getSuretySubjectCode().equals(keyValueVO.getKey())){
                    redmApplyInfo.setSuretySubjectNm(keyValueVO.getValue());
                    break;
                }
            }
        }
        /**
         * 赎回原因
         */
        List<KeyValueVO> insRedmResonCodeList = this.sysDictionaryApiService.getKvList(PrjInsRedmInfoConstant.SYS_DIS_CODE_REDM_008, CapitalConstant.SYSCD, CapitalConstant.SYSORG);
        for(KeyValueVO vo : insRedmResonCodeList){
            if(vo.getKey().equals(redmApplyInfo.getInsRedmResonCode())){
                redmApplyInfo.setInsRedmResonNm(vo.getValue());
            }
        }
        /**
         * 具体原因
         */
        List<SysDictionaryDTO> insRedmDetailResonCodeList = this.sysDictionaryApiService.searchChild(CapitalConstant.SYSCD, CapitalConstant.SYSORG, PrjInsRedmInfoConstant.SYS_DIS_CODE_REDM_009, redmApplyInfo.getInsRedmResonCode());
        for(SysDictionaryDTO sysDictionaryDTO : insRedmDetailResonCodeList) {
            if(sysDictionaryDTO.getCode().equals(redmApplyInfo.getInsRedmDetailResonCode())){
                redmApplyInfo.setInsRedmDetailResonNm(sysDictionaryDTO.getCodeNm());
            }
        }
        BaseLogUtils.newLogger("修改资管赎回详情页面,查询赎回信息结束").setLogOperType(LogOperEnum.REQ).setKeys("toRedmInfoPage","redmApplyInfo="+ JSON.toJSONString(redmApplyInfo),this.getRequestParameter(request)).info();
        view.addObject("redm", redmApplyInfo);
        view.addObject("repayMode", repayMode);
        view.addObject("suretySubjectCodeList", suretySubjectCodeList);
        view.addObject("isShowInsRedmInterfaceInfo", isShowInsRedmInterfaceInfo);
        view.addObject("redm", redmApplyInfo);
        view.addObject("pkId", id);
        view.addObject("tabNm", PrjInsRedmInfoConstant.RedmFile.FILE_DEDU_PROVE_TAB_NM);
        return view;
    }

    /**
     * 资管赎回资金部修改页面
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/toModifyRedmInfoPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toModifyRedmInfoPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("修改资管赎回详情页面").setLogOperType(LogOperEnum.REQ).setKeys("toModifyRedmInfoPage",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView view = new ModelAndView("institution/redm/modifyRedmInfoPage");
        String id = request.getParameter("redmId");
        PrjInsRedmInfoQC qc = new PrjInsRedmInfoQC();
        if (StringUtils.isEmpty(id)) {
            BaseLogUtils.newLogger("请求参数id不能为空").setLogOperType(LogOperEnum.REQ).setKeys("toModifyRedmInfoPage",id,CurrentThreadContext.getCurrentUserName()).info();
            return view;
        }
        qc.setId(Long.valueOf(id));
        PrjInsRedmInfoVO redmApplyInfo = this.prjInsRedmInfoService.searchAssetsRedmInfo(qc);
        /**
         * 配置项 是否展示资方接口赎回信息
         */
        int isShowInsRedmInterfaceInfo = this.prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(redmApplyInfo.getInsCode(),PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C041);
        /**
         * 配置项 回购主体
         */
        List<KeyValueVO> suretySubjectCodeList = this.prjInsRedmInterfaceInfoService.getSuretySubjectCodeList(redmApplyInfo.getInsCode());
        /**
         * 配置项 机构是否需要核销逾期才能试算
         */
        int isChargeOffOvd = 0;
        if(BaseConstant.IS_YESNO_YES == redmApplyInfo.getIsOverdue()){
            isChargeOffOvd = this.prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(redmApplyInfo.getInsCode(),PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C042);
        }

        /**
         * 配置项 付款方式
         */
        int repayMode = this.prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(redmApplyInfo.getInsCode(),PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C044);
        /**
         * 配置项 我司赎回付款账户
         */
        BankAccInfoQueryCondition bankAccInfoQueryCondition = new BankAccInfoQueryCondition();
        bankAccInfoQueryCondition.setFundRasInsId(redmApplyInfo.getFundRasInsId());
        bankAccInfoQueryCondition.setAccTypCd(PrjInsRedmInfoConstant.WS_REDM_PAYMENT_ACCOUNT);
        List<BankAccInfoDTO> redmPaymentAccountDtoList = bankAccInfoApiService.searchList(bankAccInfoQueryCondition);
        /**
         * 配置项 资方赎回收款账户
         */
        bankAccInfoQueryCondition.setAccTypCd(PrjInsRedmInfoConstant.ZF_REDM_PAYEE_ACCOUNT);
        List<BankAccInfoDTO> redmPayeeAccountDtoList = bankAccInfoApiService.searchList(bankAccInfoQueryCondition);

        /**
         * 赎回原因
         */
        List<KeyValueVO> insRedmResonCodeList = this.sysDictionaryApiService.getKvList(PrjInsRedmInfoConstant.SYS_DIS_CODE_REDM_008, CapitalConstant.SYSCD, CapitalConstant.SYSORG);
        for(KeyValueVO vo : insRedmResonCodeList){
            if(vo.getKey().equals(redmApplyInfo.getInsRedmResonCode())){
                redmApplyInfo.setInsRedmResonNm(vo.getValue());
            }
        }
        /**
         * 具体原因
         */
        List<SysDictionaryDTO> insRedmDetailResonCodeList = this.sysDictionaryApiService.searchChild(CapitalConstant.SYSCD, CapitalConstant.SYSORG, PrjInsRedmInfoConstant.SYS_DIS_CODE_REDM_009, redmApplyInfo.getInsRedmResonCode());
        for(SysDictionaryDTO sysDictionaryDTO : insRedmDetailResonCodeList) {
            if(sysDictionaryDTO.getCode().equals(redmApplyInfo.getInsRedmDetailResonCode())){
                redmApplyInfo.setInsRedmDetailResonNm(sysDictionaryDTO.getCodeNm());
            }
        }
        BaseLogUtils.newLogger("修改资管赎回详情页面,查询赎回信息结束").setLogOperType(LogOperEnum.REQ).setKeys("toModifyRedmInfoPage","redmApplyInfo="+ JSON.toJSONString(redmApplyInfo),this.getRequestParameter(request)).info();
        view.addObject("redm", redmApplyInfo);
        view.addObject("repayMode", repayMode);
        view.addObject("isChargeOffOvd", isChargeOffOvd);
        view.addObject("suretySubjectCodeList", suretySubjectCodeList);
        view.addObject("redmPayeeAccountDtoList", redmPayeeAccountDtoList);
        view.addObject("redmPaymentAccountDtoList", redmPaymentAccountDtoList);
        view.addObject("isShowInsRedmInterfaceInfo", isShowInsRedmInterfaceInfo);
        view.addObject("pkId", id);
        view.addObject("tabNm", PrjInsRedmInfoConstant.RedmFile.FILE_DEDU_PROVE_TAB_NM);
        return view;
    }

    /**
     * 资管赎回客户经理修改页面
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/toCustomerManagerModifyRedmInfoPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toCustomerManagerModifyRedmInfoPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("修改客户经理资管赎回详情页面").setLogOperType(LogOperEnum.REQ).setKeys("toCustomerManagerModifyRedmInfoPage",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView view = new ModelAndView("institution/redm/customerManagerModifyRedmInfoPage");
        String id = request.getParameter("redmId");
        PrjInsRedmInfoQC qc = new PrjInsRedmInfoQC();
        if (StringUtils.isEmpty(id)) {
            BaseLogUtils.newLogger("请求参数id不能为空").setLogOperType(LogOperEnum.REQ).setKeys("toCustomerManagerModifyRedmInfoPage",id,CurrentThreadContext.getCurrentUserName()).info();
            return view;
        }
        qc.setId(Long.valueOf(id));
        PrjInsRedmInfoVO redmApplyInfo = this.prjInsRedmInfoService.searchAssetsRedmInfo(qc);

        /**
         * 赎回原因
         */
        List<KeyValueVO> insRedmResonCodeList = this.sysDictionaryApiService.getKvList(PrjInsRedmInfoConstant.SYS_DIS_CODE_REDM_008, CapitalConstant.SYSCD, CapitalConstant.SYSORG);
        for(KeyValueVO vo : insRedmResonCodeList){
            if(vo.getKey().equals(redmApplyInfo.getInsRedmResonCode())){
                redmApplyInfo.setInsRedmResonNm(vo.getValue());
            }
        }
        /**
         * 具体原因
         */
        List<SysDictionaryDTO> insRedmDetailResonCodeList = this.sysDictionaryApiService.searchChild(CapitalConstant.SYSCD, CapitalConstant.SYSORG, PrjInsRedmInfoConstant.SYS_DIS_CODE_REDM_009, redmApplyInfo.getInsRedmResonCode());
        for(SysDictionaryDTO sysDictionaryDTO : insRedmDetailResonCodeList) {
            if(sysDictionaryDTO.getCode().equals(redmApplyInfo.getInsRedmDetailResonCode())){
                redmApplyInfo.setInsRedmDetailResonNm(sysDictionaryDTO.getCodeNm());
            }
        }
        BaseLogUtils.newLogger("修改客户经理资管赎回详情页面,查询赎回信息结束").setLogOperType(LogOperEnum.REQ).setKeys("toCustomerManagerModifyRedmInfoPage","redmApplyInfo="+ JSON.toJSONString(redmApplyInfo),"pkId="+id+",tabNm="+PrjInsRedmInfoConstant.RedmFile.FILE_DEDU_PROVE_TAB_NM,this.getRequestParameter(request)).info();
        view.addObject("redm", redmApplyInfo);
        view.addObject("pkId", id);
        view.addObject("tabNm", PrjInsRedmInfoConstant.RedmFile.FILE_DEDU_PROVE_TAB_NM);
        return view;
    }

    /**
     * 资管赎回详情页面
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initRedmInfo.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object initRedmInfo(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("资管赎回详情页面").setLogOperType(LogOperEnum.REQ).setKeys("initRedmInfo",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        String id = request.getParameter("redmId");
        PrjInsRedmInfoQC qc = new PrjInsRedmInfoQC();
        if (StringUtils.isEmpty(id)) {
            BaseLogUtils.newLogger("请求参数id不能为空").setLogOperType(LogOperEnum.REQ).setKeys("initRedmInfo",id,CurrentThreadContext.getCurrentUserName()).info();
            return null;
        }
        qc.setId(Long.valueOf(id));
        PrjInsRedmInfoVO redmApplyInfo = this.prjInsRedmInfoService.searchAssetsRedmInfo(qc);
        return redmApplyInfo;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        BaseLogUtils.newLogger("新增对象").setLogOperType(LogOperEnum.REQ).setKeys("add",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
        String prjId = request.getParameter("prjId");
        if(StringUtils.isEmpty(prjId)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("项目ID为空！");
            return result;
        }
        try {
            /**
             * 验证封装数据
             */
            PrjInsRedmInfoVO prjInsRedmInfoVO = new PrjInsRedmInfoVO();
            result = verifyRedmDataParam(request,prjInsRedmInfoVO,result);
            if(BaseConstant.IS_YESNO_YES == result.getSuccess()){
                /**
                 * 校验我司放款数据
                 */
                DataResultDTO resultDTO = this.prjInsRedmInfoService.addPrjInsRedmInfoAndVerifyFlow(prjInsRedmInfoVO);
                if(resultDTO.getSuccess() == BaseConstant.IS_YESNO_YES){
                    /**
                     * 校验试算数据
                     */
                    resultDTO = this.prjInsRedmInfoService.verifyInsRedmTrialData(prjInsRedmInfoVO);
                    BaseLogUtils.newLogger("资管资产赎回,添加赎回记录,校验试算数据结束").setKeys("add","resultDTO="+ JSON.toJSONString(resultDTO)).info();
                    if(BaseConstant.IS_YESNO_YES == resultDTO.getSuccess()){
                        /**
                         * 添加试算数据 添加赎回记录
                         */
                        PrjInsRedmInterfaceInfoDTO prjInsRedmInterfaceInfoDTO = null;
                        if(null != resultDTO.getData()){
                            prjInsRedmInterfaceInfoDTO = (PrjInsRedmInterfaceInfoDTO)resultDTO.getData();
                            /**
                             * 更新赎回记录中的赎回本金 赎回利息 赎回金额合计
                             */
                            if(null != prjInsRedmInterfaceInfoDTO.getRedmAmt() && 0 != prjInsRedmInterfaceInfoDTO.getRedmAmt()){
                                prjInsRedmInfoVO.setRedmTotalAmt(prjInsRedmInterfaceInfoDTO.getRedmAmt().doubleValue());
                            }
                            if(null != prjInsRedmInterfaceInfoDTO.getPrincipalAmt() && 0 != prjInsRedmInterfaceInfoDTO.getPrincipalAmt()){
                                prjInsRedmInfoVO.setRedmPrinAmt(prjInsRedmInterfaceInfoDTO.getPrincipalAmt().doubleValue());
                            }
                            if(null != prjInsRedmInterfaceInfoDTO.getInterestAmt() && 0 != prjInsRedmInterfaceInfoDTO.getInterestAmt()){
                                prjInsRedmInfoVO.setRedmPnlAmt(prjInsRedmInterfaceInfoDTO.getInterestAmt().doubleValue());
                            }
                        }
                        PrjInsRedmInfoDTO prjInsRedmInfoDTO = PrjInsRedmInfoVOTransform.toDTO(prjInsRedmInfoVO);
                        resultDTO = this.prjInsRedmInfoService.addPrjInsRedmData(prjInsRedmInfoDTO,prjInsRedmInterfaceInfoDTO);
                        BaseLogUtils.newLogger("资管资产赎回,添加赎回记录,试算数据结束").setKeys("add","resultDTO="+ JSON.toJSONString(resultDTO),"prjInsRedmInfoVO="+ JSON.toJSONString(prjInsRedmInfoVO),"prjInsRedmInfoDTO="+ JSON.toJSONString(prjInsRedmInfoDTO)).info();
                        if(null != resultDTO.getData()){
                            prjInsRedmInfoVO.setId((Long)resultDTO.getData());
                            prjInsRedmInfoDTO.setId(prjInsRedmInfoVO.getId());
                            /**
                             *上传文件
                             */
                            result = this.uploadAttchment(request, result, prjInsRedmInfoVO.getId());
                            /**
                             *发起流程
                             */
                            FlowStartedDTO flowStartedDTO = this.prjInsRedmInfoService.addRedmAndFlowStart(prjInsRedmInfoDTO, CurrentThreadContext.getCurrentUserId(), CurrentThreadContext.getCurrentUserName()
                                    , CurrentThreadContext.getCurrentBuOrgCd(), CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd(),0);
                            if(null == flowStartedDTO){
                                result.setSuccess(BaseConstant.IS_YESNO_NO);
                                result.setInfo("流程发起失败!");
                                return result;
                            }
                        }else{
                            result.setSuccess(BaseConstant.IS_YESNO_NO);
                            if(StringUtils.isEmpty(resultDTO.getInfo())){
                                result.setInfo("添加试算数据 添加赎回记录失败");
                            }
                            return result;
                        }
                    }else{
                        result.setSuccess(BaseConstant.IS_YESNO_NO);
                        if(StringUtils.isEmpty(resultDTO.getInfo())){
                            result.setInfo("添加赎回记录,校验资方试算数据失败");
                        }else{
                            result.setInfo(resultDTO.getInfo());
                        }
                        return result;
                    }

                }else{
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo(resultDTO.getInfo());
                    return result;
                }
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("新增对象失败").setLogOperType(LogOperEnum.REQ).setKeys("add",prjId,CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0001);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newLogger("新增对象失败").setLogOperType(LogOperEnum.REQ).setKeys("add",prjId,CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;
    }


    /**
     * 客户经理新增并发起流程
     */
    @RequestMapping(value = "/customerManagerAdd.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object customerManagerAdd(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        BaseLogUtils.newLogger("新增对象").setLogOperType(LogOperEnum.REQ).setKeys("add",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
        String prjId = request.getParameter("prjId");
        if(StringUtils.isEmpty(prjId)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("项目ID为空！");
            return result;
        }
        try {
            /**
             * 验证封装数据
             */
            PrjInsRedmInfoVO prjInsRedmInfoVO = new PrjInsRedmInfoVO();
            result = verifyRedmDataParam(request,prjInsRedmInfoVO,result);
            if(BaseConstant.IS_YESNO_YES == result.getSuccess()){
                DataResultDTO resultDTO = this.prjInsRedmInfoService.addPrjInsRedmInfoAndVerifyFlow(prjInsRedmInfoVO);
                if(resultDTO.getSuccess() == BaseConstant.IS_YESNO_YES){
                    /**
                     * 添加赎回记录
                     */
                    PrjInsRedmInfoDTO prjInsRedmInfoDTO = PrjInsRedmInfoVOTransform.toDTO(prjInsRedmInfoVO);
                    resultDTO = this.prjInsRedmInfoService.addPrjInsRedmData(prjInsRedmInfoDTO,null);
                    if(BaseConstant.IS_YESNO_YES == resultDTO.getSuccess() && null != resultDTO.getData()){
                        prjInsRedmInfoVO.setId((Long)resultDTO.getData());
                        prjInsRedmInfoDTO.setId(prjInsRedmInfoVO.getId());
                        /**
                         *上传文件
                         */
                        result = this.uploadAttchment(request, result, prjInsRedmInfoVO.getId());
                        /**
                         *发起流程
                         */
                        FlowStartedDTO flowStartedDTO = this.prjInsRedmInfoService.addRedmAndFlowStart(prjInsRedmInfoDTO, CurrentThreadContext.getCurrentUserId(), CurrentThreadContext.getCurrentUserName()
                                , CurrentThreadContext.getCurrentBuOrgCd(), CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd(),1);
                        if(null == flowStartedDTO){
                            result.setSuccess(BaseConstant.IS_YESNO_NO);
                            result.setInfo("流程发起失败!");
                        }
                    }else{
                        result.setSuccess(BaseConstant.IS_YESNO_NO);
                        result.setInfo("添加赎回记录失败");
                    }

                }else{
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo(resultDTO.getInfo());
                    return result;
                }
            }else{
                return result;
            }

        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("新增对象失败").setLogOperType(LogOperEnum.REQ).setKeys("add",prjId,CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0001);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newLogger("新增对象失败").setLogOperType(LogOperEnum.REQ).setKeys("add",prjId,CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;
    }

    /**
     * 资金部维护节点修改
     */
    @RequestMapping(value = "/modify.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        BaseLogUtils.newLogger("资管赎回,修改赎回记录对象").setLogOperType(LogOperEnum.REQ).setKeys("modify",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        Long redmId = Long.valueOf(request.getParameter("redmId"));
        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
        try {
            /**
             * 验证封装数据
             */
            PrjInsRedmInfoQC qc = new PrjInsRedmInfoQC();
            qc.setId(redmId);
            BaseLogUtils.newLogger("资管赎回,开始查询赎回记录对象").setLogOperType(LogOperEnum.REQ).setKeys("modify","PrjInsRedmInfoQC="+ JSON.toJSONString(qc),this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
            PrjInsRedmInfoVO entity = this.prjInsRedmInfoService.searchAssetsRedmApplyInfo(qc);
            BaseLogUtils.newLogger("资管赎回,查询赎回记录对象结束").setLogOperType(LogOperEnum.REQ).setKeys("modify","entity="+ JSON.toJSONString(entity),this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
            /**
             * 赎回本金
             */
            String redmPrinAmt = request.getParameter("redmPrinAmt");
            /**
             * 赎回利息
             */
            String redmIntAmt = request.getParameter("redmIntAmt");
            /**
             * 赎回罚息
             */
            String redmPnlAmt = request.getParameter("redmPnlAmt");
            /**
             * 资方放款状态
             */
            String payerStsCd = request.getParameter("payerStsCd");
            /**
             * 是否上报征信
             */
            String isSubmitCreditRDStr = request.getParameter("isSubmitCreditRD");
            int isSubmitCreditRD = 0;
            /**
             * 回购主体编码
             */
            String suretySubjectCode = request.getParameter("suretySubjectCode");
            /**
             * 是否已经线下赎回
             */
            String offlineSettle = request.getParameter("offlineSettle");
            /**
             * 线下赎回日期
             */
            String insRedmTm = request.getParameter("insRedmTm");
            /**
             * 赎回金额
             */
            String redmTotalAmt = request.getParameter("redmTotalAmt");

            /**
             * 赎回原因
             */
            String insRedmReson = request.getParameter("insRedmReson");
            /**
             * 具体原因
             */
            String insRedmDetailReson = request.getParameter("insRedmDetailReson");
            /**
             * 其他原因
             */
            String otherInsRedmReson = request.getParameter("otherInsRedmReson");

            /**
             * 我司赎回付款账户
             */
            String redmPaymentAccountNum = request.getParameter("redmPaymentAccountNum");
            /**
             * 资方赎回收款账户
             */
            String redmPayeeAccountNum = request.getParameter("redmPayeeAccountNum");
            /**
             * 转账附言
             */
            String paymentReason = request.getParameter("paymentReason");
            /**
             * 付款方式
             */
            String repayMode = request.getParameter("repayMode");

            /**
             * 其他原因字数限制
             */
            if(StringUtils.isNotEmpty(otherInsRedmReson)){
                if(otherInsRedmReson.length() > 100){
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo("验证数据失败.其他原因字数过多,超过100");
                    return dataResultVO;
                }
            }

            if(StringUtils.isEmpty(isSubmitCreditRDStr)){
                BaseLogUtils.newLogger("验证数据失败.是否上报征信为空").setKeys("modify","isSubmitCreditRDStr="+isSubmitCreditRDStr,CurrentThreadContext.getCurrentUserName()).info();
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("验证数据失败.是否上报征信为空");
                return dataResultVO;
            }else{
                isSubmitCreditRD = Integer.valueOf(isSubmitCreditRDStr);
            }

            if(StringUtils.isEmpty(suretySubjectCode)){
                BaseLogUtils.newLogger("验证数据失败.融担主体编码为空").setKeys("modify","suretySubjectCode="+suretySubjectCode,CurrentThreadContext.getCurrentUserName()).info();
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("验证数据失败.融担主体编码为空");
                return dataResultVO;
            }
            /**
             * 已放款才进行校验
             */
            if(PrjPrdPaySchMConstant.PAYER_STS_CD_PAID.equals(payerStsCd)){
                /**
                 * 拜特付款需要填写转账附言
                 */
                if(StringUtils.isNotEmpty(repayMode) && "1".equals(repayMode)){
                    if(StringUtils.isEmpty(paymentReason)){
                        BaseLogUtils.newLogger("验证数据失败.拜特付款,转账备注不能为空").setKeys("verifyRedmDataParam","paymentReason="+paymentReason,CurrentThreadContext.getCurrentUserName()).info();
                        dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                        dataResultVO.setInfo("验证数据失败.拜特付款,转账备注不能为空");
                        return dataResultVO;
                    }
                }

                if(StringUtils.isEmpty(redmPaymentAccountNum)){
                    BaseLogUtils.newLogger("验证数据失败.我司赎回付款账户为空").setKeys("modify","redmPaymentAccountNum="+redmPaymentAccountNum,CurrentThreadContext.getCurrentUserName()).info();
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo("验证数据失败.请维护我司赎回付款账户");
                    return dataResultVO;
                }

                if(StringUtils.isEmpty(redmPayeeAccountNum)){
                    BaseLogUtils.newLogger("验证数据失败.资方赎回收款账户为空").setKeys("modify","redmPayeeAccountNum="+redmPayeeAccountNum,CurrentThreadContext.getCurrentUserName()).info();
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo("验证数据失败.请维护资方赎回收款账户");
                    return dataResultVO;
                }
                if("1".equals(offlineSettle)){
                    /**
                     * 是否支持线下赎回
                     */
                    int canOfflineRedm = prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(entity.getInsCode(),PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C043);
                    if(BaseConstant.IS_YESNO_NO == canOfflineRedm){
                        BaseLogUtils.newLogger("验证数据失败.机构不支持线下赎回,请重新选择").setKeys("modify","canOfflineRedm="+canOfflineRedm,CurrentThreadContext.getCurrentUserName()).info();
                        dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                        dataResultVO.setInfo("验证数据失败.机构不支持线下赎回,请重新选择");
                        return dataResultVO;
                    }
                    /**
                     * 已经线下赎回 线下赎回时间不能为空
                     */
                    if(StringUtils.isBlank(insRedmTm)){
                        BaseLogUtils.newLogger("验证数据失败.线下赎回时间不能为空").setKeys("modify","insRedmTm="+insRedmTm,CurrentThreadContext.getCurrentUserName()).info();
                        dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                        dataResultVO.setInfo("验证数据失败.线下赎回时间不能为空");
                        return dataResultVO;
                    }

                    /**
                     * 已经线下赎回 赎回本金不能为空
                     */
                    if(StringUtils.isEmpty(redmPrinAmt)){
                        BaseLogUtils.newLogger("验证数据失败.赎回本金为空").setKeys("modify","redmPrinAmt="+redmPrinAmt,CurrentThreadContext.getCurrentUserName()).info();
                        dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                        dataResultVO.setInfo("验证数据失败.赎回本金不能为空");
                        return dataResultVO;
                    }

                    /**
                     * 已经线下赎回 赎回利息不能为空
                     */
                    if(StringUtils.isEmpty(redmIntAmt)){
                        BaseLogUtils.newLogger("验证数据失败.赎回利息为空").setKeys("modify","redmIntAmt="+redmIntAmt,CurrentThreadContext.getCurrentUserName()).info();
                        dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                        dataResultVO.setInfo("验证数据失败.赎回利息不能为空");
                        return dataResultVO;
                    }
                }

            }

            /**
             * 赎回本金
             */
            if(StringUtils.isNotBlank(redmPrinAmt)){
                entity.setRedmPrinAmt(DecimalUtils.convertYuanToFen(Double.valueOf(redmPrinAmt)).doubleValue());
            }
            /**
             * 赎回利息
             */
            if(StringUtils.isNotBlank(redmIntAmt)){
                entity.setRedmIntAmt(DecimalUtils.convertYuanToFen(Double.valueOf(redmIntAmt)).doubleValue());
            }
            /**
             * 赎回罚息
             */
            if(StringUtils.isNotBlank(redmPnlAmt)){
                entity.setRedmPnlAmt(DecimalUtils.convertYuanToFen(Double.valueOf(redmPnlAmt)).doubleValue());
            }
            /**
             * 赎回金额
             */
            if(StringUtils.isNotBlank(redmTotalAmt) && Double.valueOf(redmTotalAmt).longValue() != 0){
                entity.setRedmTotalAmt(DecimalUtils.convertYuanToFen(Double.valueOf(redmTotalAmt)).doubleValue());
            }else{
                if(null != entity.getRedmPrinAmt() && null != entity.getRedmIntAmt()){
                    entity.setRedmTotalAmt(DecimalUtils.add(entity.getRedmPrinAmt(),entity.getRedmIntAmt()));
                }
            }
            if("1".equals(offlineSettle)){
                entity.setInsRedmTm(DateUtils.formatStringToDate(insRedmTm, DateUtils.YYYY_MM_DD));
            }

            entity.setIsSubmitCreditRD(isSubmitCreditRD);
            entity.setSuretySubjectCode(suretySubjectCode);
            /**
             * 是否线下赎回
             */
            entity.setOfflineSettle(Integer.valueOf(offlineSettle));
            /**
             * 是否结清
             */
            entity.setSettleStatus(PrjInsRedmInfoConstant.PRJ_INS_REDM_RESULT_UNCOMMIT);


            /**
             * 赎回原因
             */
            entity.setInsRedmResonCode(insRedmReson);
            /**
             * 具体原因
             */
            entity.setInsRedmDetailResonCode(insRedmDetailReson);
            /**
             *其他原因
             */
            entity.setOtherInsRedmReson(otherInsRedmReson);

            /**
             * 我司赎回付款账户账号
             */
            if(StringUtils.isNotEmpty(redmPaymentAccountNum)){
                entity.setRedmPaymentAccountNum(redmPaymentAccountNum);
            }
            /**
             * 资方赎回收款账户账号
             */
            if(StringUtils.isNotEmpty(redmPayeeAccountNum)){
                entity.setRedmPayeeAccountNum(redmPayeeAccountNum);
            }

            /**
             * 转账附言
             */
            entity.setPaymentReason(paymentReason);

            if(BaseConstant.IS_YESNO_YES == dataResultVO.getSuccess()){
                /**
                 * 校验试算数据
                 */
                DataResultDTO dataResultDTO = this.prjInsRedmInfoService.verifyInsRedmTrialData(entity);
                BaseLogUtils.newLogger("资管赎回,修改赎回记录,校验试算数据结束").setKeys("modify","dataResultDTO="+ JSON.toJSONString(dataResultDTO),"entity="+ JSON.toJSONString(entity),CurrentThreadContext.getCurrentUserName()).info();
                if(BaseConstant.IS_YESNO_NO == dataResultDTO.getSuccess()){
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo(StringUtils.isNotEmpty(dataResultDTO.getInfo())?dataResultDTO.getInfo():"校验试算数据失败");
                    return dataResultVO;
                }
                if (StringUtils.isNotEmpty(entity.getId())) {
                    /**
                     * 查询之前是否有试算记录
                     */
                    PrjInsRedmInterfaceInfoQC prjInsRedmInterfaceInfoQC =new PrjInsRedmInterfaceInfoQC();
                    prjInsRedmInterfaceInfoQC.setPaySchId(entity.getPaySchId());
                    prjInsRedmInterfaceInfoQC.setPrjId(entity.getPrjId());
                    prjInsRedmInterfaceInfoQC.setOperationType(PrjInsRedmInterfaceInfoConstant.INS_REDM_INTERFACE_OPERATION_TYPE_0);
                    List<PrjInsRedmInterfaceInfoVO> prjInsRedmInterfaceInfoVOList = this.prjInsRedmInterfaceInfoService.selectInsRedmInterfaceInfoList(prjInsRedmInterfaceInfoQC);
                    BaseLogUtils.newLogger("资管赎回,修改赎回记录,查询资方试算结果结束").setKeys("modify","prjInsRedmInterfaceInfoVOList="+ JSON.toJSONString(prjInsRedmInterfaceInfoVOList),"prjInsRedmInterfaceInfoQC="+ JSON.toJSONString(prjInsRedmInterfaceInfoQC),CurrentThreadContext.getCurrentUserName()).info();
                    /**
                     * 添加OR更新试算结果
                     */
                    PrjInsRedmInterfaceInfoDTO prjInsRedmInterfaceInfoDTO = (PrjInsRedmInterfaceInfoDTO)dataResultDTO.getData();
                    if(null != prjInsRedmInterfaceInfoDTO){
                        if(CollectionUtils.isNotEmpty(prjInsRedmInterfaceInfoVOList)){
                            this.prjInsRedmInterfaceInfoService.modifyPrjInsRedmInterfaceInfoVO(PrjInsRedmInterfaceInfoVOTransform.toVO(prjInsRedmInterfaceInfoDTO));
                        }else{
                            this.prjInsRedmInterfaceInfoService.addPrjInsRedmInterfaceInfoVO(PrjInsRedmInterfaceInfoVOTransform.toVO(prjInsRedmInterfaceInfoDTO));
                        }
                        /**
                         * 非线下结清 需要更新赎回本金 赎回利息 赎回金额合计
                         */
                        if(null != prjInsRedmInterfaceInfoDTO.getRedmAmt() && 0 != prjInsRedmInterfaceInfoDTO.getRedmAmt()){
                            entity.setRedmTotalAmt(prjInsRedmInterfaceInfoDTO.getRedmAmt().doubleValue());
                        }
                        if(null != prjInsRedmInterfaceInfoDTO.getPrincipalAmt() && 0 != prjInsRedmInterfaceInfoDTO.getPrincipalAmt()){
                            entity.setRedmPrinAmt(prjInsRedmInterfaceInfoDTO.getPrincipalAmt().doubleValue());
                        }
                        if(null != prjInsRedmInterfaceInfoDTO.getInterestAmt() && 0 != prjInsRedmInterfaceInfoDTO.getInterestAmt()){
                            entity.setRedmPnlAmt(prjInsRedmInterfaceInfoDTO.getInterestAmt().doubleValue());
                        }
                    }
                    redmId = entity.getId();
                    boolean modifResult = this.prjInsRedmInfoService.modify(entity);
                    BaseLogUtils.newLogger("资管赎回,修改赎回记录,修改赎回记录结束").setKeys("modify","entity="+ JSON.toJSONString(entity),"prjInsRedmInterfaceInfoDTO="+ JSON.toJSONString(prjInsRedmInterfaceInfoDTO),CurrentThreadContext.getCurrentUserName()).info();

                    if(!modifResult){
                        dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                        dataResultVO.setInfo("保存数据失败");
                        return dataResultVO;
                    }

                    /**
                     *文件上传
                     */
                    String hasFile = request.getParameter("hasFile");
                    if(StringUtils.isNotEmpty(hasFile) && "yes".equals(hasFile)){
                        dataResultVO = this.uploadAttchment(request, dataResultVO, redmId);
                    }
                    dataResultVO.setData(redmId);
                } else {
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo("请求数据不全,未找到主键ID!");
                }
            }
            BaseLogUtils.newLogger("修改成功").setLogOperType(LogOperEnum.REQ).setKeys("modify",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("修改对象失败,").setLogOperType(LogOperEnum.REQ).setKeys("modify",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0099);
        } catch (Exception ex) {
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newLogger("修改对象失败,").setLogOperType(LogOperEnum.REQ).setKeys("modify",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return dataResultVO;
    }

    /**
     * 客户经理节点修改
     */
    @RequestMapping(value = "/customerManagerModify.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object customerManagerModify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        BaseLogUtils.newLogger("资管赎回,客户经理节点修改赎回记录对象").setLogOperType(LogOperEnum.REQ).setKeys("customerManagerModify",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        Long redmId = Long.valueOf(request.getParameter("redmId"));
        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
        try {
            BaseLogUtils.newLogger("资管赎回,客户经理节点,开始查询赎回记录对象").setLogOperType(LogOperEnum.REQ).setKeys("customerManagerModify","redmId="+ redmId,this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
            PrjInsRedmInfoVO entity = this.prjInsRedmInfoService.selectById(redmId);
            BaseLogUtils.newLogger("资管赎回,客户经理节点,查询赎回记录对象结束").setLogOperType(LogOperEnum.REQ).setKeys("customerManagerModify","entity="+ JSON.toJSONString(entity),this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
            /**
             * 赎回原因
             */
            String insRedmReson = request.getParameter("insRedmReson");
            /**
             * 具体原因
             */
            String insRedmDetailReson = request.getParameter("insRedmDetailReson");
            /**
             * 其他原因
             */
            String otherInsRedmReson = request.getParameter("otherInsRedmReson");

            /**
             * 其他原因字数限制
             */
            if(StringUtils.isNotEmpty(otherInsRedmReson)){
                if(otherInsRedmReson.length() > 100){
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo("验证数据失败.其他原因字数过多,超过100");
                    return dataResultVO;
                }
            }

            /**
             * 赎回原因
             */
            entity.setInsRedmResonCode(insRedmReson);
            /**
             * 具体原因
             */
            entity.setInsRedmDetailResonCode(insRedmDetailReson);
            /**
             *其他原因
             */
            entity.setOtherInsRedmReson(otherInsRedmReson);

            if(BaseConstant.IS_YESNO_YES == dataResultVO.getSuccess()){
                if (StringUtils.isNotEmpty(entity.getId())) {
                    redmId = entity.getId();
                    boolean modifResult = this.prjInsRedmInfoService.modify(entity);
                    BaseLogUtils.newLogger("资管赎回,客户经理节点,修改赎回记录,修改赎回记录结束").setKeys("customerManagerModify","entity="+ JSON.toJSONString(entity),CurrentThreadContext.getCurrentUserName()).info();
                    if(!modifResult){
                        dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                        dataResultVO.setInfo("保存数据失败");
                        return dataResultVO;
                    }

                    /**
                     *文件上传
                     */
                    String hasFile = request.getParameter("hasFile");
                    if(StringUtils.isNotEmpty(hasFile) && "yes".equals(hasFile)){
                        dataResultVO = this.uploadAttchment(request, dataResultVO, redmId);
                    }
                    dataResultVO.setData(redmId);
                } else {
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo("请求数据不全,未找到主键ID!");
                }
            }
            BaseLogUtils.newLogger("资管赎回,客户经理节点,修改成功").setLogOperType(LogOperEnum.REQ).setKeys("customerManagerModify",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("资管赎回,客户经理节点,修改对象失败,").setLogOperType(LogOperEnum.REQ).setKeys("customerManagerModify",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0099);
        } catch (Exception ex) {
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newLogger("资管赎回,客户经理节点,修改对象失败,").setLogOperType(LogOperEnum.REQ).setKeys("customerManagerModify",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return dataResultVO;
    }


    /**
     * 上传附件
     *
     * @param request
     * @param result
     * @param id
     */
    private DataResultVO uploadAttchment(HttpServletRequest request, DataResultVO result, Long id) {
        String attchmnt = request.getParameter("fileParams");
        if (StringUtils.isNotEmpty(attchmnt)) {
            //上传解析
            try {
                String cfgCd = PrjInsRedmInfoConstant.RedmFile.FILE_DEDU_PROVE_CFG_CD;
                String cfgDtlCd = PrjInsRedmInfoConstant.RedmFile.FILE_DEDU_PROVE_CFGDTLCD_10;
                String tabNm = PrjInsRedmInfoConstant.RedmFile.FILE_DEDU_PROVE_TAB_NM;
                String cfgOrgCd = PrjInsRedmInfoConstant.RedmFile.FILE_DEDU_PROVE_CFGORG;
                /**
                 * 删除之前的附件
                 */
                SysUlFilesRecQueryCondition qc = new SysUlFilesRecQueryCondition();
                qc.setPkId(String.valueOf(id));
                qc.setCfgCd(cfgCd);
                qc.setTabNm(tabNm);
                this.sysUlFilesRecService.removeByCondition(qc);
                Boolean attchmntPass = this.sysUlFilesRecService.addAttchmnt(String.valueOf(id), attchmnt, cfgCd, cfgDtlCd, tabNm, "资管资产赎回附件!", null, null, false, cfgOrgCd);
                if (null == attchmntPass || attchmntPass == false) {
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo(result.getInfo() + "-附件上传失败!");
                    BaseLogUtils.newLogger(result.getInfo() + "-附件上传失败attchmntPass is null or false !").setKeys("uploadAttchment").info();
                }
            } catch (Exception e) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(result.getInfo() + "附件上传失败!");
                BaseLogUtils.newLogger(result.getInfo() + "-附件上传失败!").setKeys("uploadAttchment",CurrentThreadContext.getCurrentUserName()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            }
        }
        return result ;
    }






    /**
     * 检查机构是否可以进行赎回操作
     */
    @RequestMapping(value = "/insCanRedeem.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object insCanRedeem(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_NO, "机构不可进行赎回操作!");
        String prjId = request.getParameter("prjId");
        String insCode = request.getParameter("insCode");
        if(StringUtils.isEmpty(prjId)){
            result.setInfo("申请赎回,项目ID不能为空！");
            return result;
        }

        if(StringUtils.isEmpty(insCode)){
            result.setInfo("申请赎回,机构CODE不能为空！");
            return result;
        }
        try {
            int insCanRedeem = prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(insCode,PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C040);
            BaseLogUtils.newLogger("资管赎回机构配置").setLogOperType(LogOperEnum.REQ).setKeys("insCode="+insCode,"insCanRedeem="+insCanRedeem).info();
            if(BaseConstant.IS_YESNO_YES == insCanRedeem){
                result.setSuccess(BaseConstant.IS_YESNO_YES);
                result.setInfo("机构校验通过");
            }else{
                return result;
            }
            //浦发银行需要增加 账单应还金额合计与账单实还金额合计校验
            PrjPrdPaySchMQueryCondition prjPrdPaySchMQueryCondition = new PrjPrdPaySchMQueryCondition();
            prjPrdPaySchMQueryCondition.setPrjId(Long.valueOf(prjId));
            prjPrdPaySchMQueryCondition.setPaySchTypCd(PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_ZF);
            List<PrjPrdPaySchMDTO> prjPrdPaySchMDTOS = prjPrdPaySchMApiService.selectListByPrjId(prjPrdPaySchMQueryCondition);
            if(CollectionUtils.isEmpty(prjPrdPaySchMDTOS)){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("申请赎回,资方支付表数据不存在！");
                return result;

            }
            PrjPrdPaySchMDTO prjPrdPaySchMDTO = prjPrdPaySchMDTOS.get(0);
            BaseLogUtils.newLogger("申请赎回数据校验,查询资方支付表信息").setKeys("prjPrdPaySchMDTO="+ JSON.toJSONString(prjPrdPaySchMDTO)).info();
            if(PrjInsRedmInterfaceInfoConstant.INS_CODE_HRBANK.equalsIgnoreCase(insCode)){
                //查询资方支付表还款情况
                PrjPrdPaySchDQueryCondition condition = new PrjPrdPaySchDQueryCondition();
                condition.setFeeTypCd(CapitalConstant.CODE_FEE_TYP_CD_S01);
                condition.setPaySchId(prjPrdPaySchMDTO.getId());
                List<PrjPrdPaySchDDTO> prjPrdPaySchDDTOS = prjPaySchDApiService.searchPaySchDtlByFeeTypCd(condition);
                if(CollectionUtils.isNotEmpty(prjPrdPaySchDDTOS)){
                    //账单应还金额
                    long feeAmt = 0L;
                    //账单实还金额
                    long paidUpAmt = 0L;
                    for(PrjPrdPaySchDDTO prjPrdPaySchDDTO : prjPrdPaySchDDTOS){
                        feeAmt += prjPrdPaySchDDTO.getFeeAmt().longValue();
                        paidUpAmt += prjPrdPaySchDDTO.getPaidUpAmt().longValue();
                    }
                    BaseLogUtils.newLogger("计算资方支付表账单应还金额合计与账单实还金额合计结束").setKeys("paySchId="+condition.getPaySchId(),"应还合计feeAmt="+feeAmt,"实还合计paidUpAmt="+paidUpAmt).info();
                    if(feeAmt == paidUpAmt){
                        result.setSuccess(BaseConstant.IS_YESNO_NO);
                        result.setInfo("申请赎回,已与资方结清,无需发起赎回！");
                    }

                }else{
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo("申请赎回,资方支付表租金表数据不存在！");
                }

            }
        } catch (BaseException ex) {
            result.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("机构赎回操作校验失败").setLogOperType(LogOperEnum.REQ).setKeys("insCanRedeem",prjId,insCode).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0001);
        } catch (Exception ex) {
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newLogger("机构赎回操作校验失败").setLogOperType(LogOperEnum.REQ).setKeys("insCanRedeem",prjId,insCode).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0001);
        }

        return result;
    }


    /**
     * 添加封装数据
     *
     * @param request
     * @param entity
     * @param dataResultVO
     * @return
     */
    private DataResultVO verifyRedmDataParam(HttpServletRequest request,PrjInsRedmInfoVO entity,DataResultVO dataResultVO) {
        String redmPrinAmt = request.getParameter("redmPrinAmt");
        String redmIntAmt = request.getParameter("redmIntAmt");
        String redmPnlAmt = request.getParameter("redmPnlAmt");
        String prjId = request.getParameter("prjId");
        String payerStsCd = request.getParameter("payerStsCd");
        /**
         * 是否上报征信
         */
        String isSubmitCreditRDStr = request.getParameter("isSubmitCreditRD");
        int isSubmitCreditRD = 0;
        /**
         * 回购主体编码
         */
        String suretySubjectCode = request.getParameter("suretySubjectCode");
        /**
         * 是否已经线下赎回
         */
        String offlineSettle = request.getParameter("offlineSettle");
        /**
         * 线下赎回日期
         */
        String insRedmTm = request.getParameter("insRedmTm");
        /**
         * 赎回金额
         */
        String redmTotalAmt = request.getParameter("redmTotalAmt");
        /**
         * 赎回原因
         */
        String insRedmReson = request.getParameter("insRedmReson");
        /**
         * 具体原因
         */
        String insRedmDetailReson = request.getParameter("insRedmDetailReson");
        /**
         * 其他原因
         */
        String otherInsRedmReson = request.getParameter("otherInsRedmReson");
        /**
         * 我司赎回付款账户
         */
        String redmPaymentAccountNum = request.getParameter("redmPaymentAccountNum");
        /**
         * 资方赎回收款账户
         */
        String redmPayeeAccountNum = request.getParameter("redmPayeeAccountNum");
        /**
         * 转账附言
         */
        String paymentReason = request.getParameter("paymentReason");
        /**
         * 付款方式
         */
        String repayMode = request.getParameter("repayMode");

        /**
         * 其他原因字数限制
         */
        if(StringUtils.isNotEmpty(otherInsRedmReson)){
            if(otherInsRedmReson.length() > 100){
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("验证数据失败.其他原因字数过多,超过100");
                return dataResultVO;
            }
        }
        if(!PrjInsRedmInfoConstant.REDM_CST_MGR_ROLE_ID.equals(CurrentThreadContext.getCurrentRoleId())){
            /**
             * 拜特付款需要填写转账附言
             */
            if(StringUtils.isNotEmpty(repayMode) && "1".equals(repayMode)){
                if(StringUtils.isEmpty(paymentReason)){
                    BaseLogUtils.newLogger("验证数据失败.拜特付款,转账备注不能为空").setKeys("verifyRedmDataParam","paymentReason="+paymentReason,CurrentThreadContext.getCurrentUserName()).info();
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo("验证数据失败.拜特付款,转账备注不能为空");
                    return dataResultVO;
                }
            }
            /**
             * 客户经理不需要校验的数据
             */
            if(StringUtils.isEmpty(isSubmitCreditRDStr)){
                BaseLogUtils.newLogger("验证数据失败.是否上报征信为空").setKeys("verifyRedmDataParam","isSubmitCreditRDStr="+isSubmitCreditRDStr,CurrentThreadContext.getCurrentUserName()).info();
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("验证数据失败.是否上报征信为空");
                return dataResultVO;
            }else{
                isSubmitCreditRD = Integer.valueOf(isSubmitCreditRDStr);
            }

            if(StringUtils.isEmpty(suretySubjectCode)){
                BaseLogUtils.newLogger("验证数据失败.融担主体编码为空").setKeys("verifyRedmDataParam","suretySubjectCode="+suretySubjectCode,CurrentThreadContext.getCurrentUserName()).info();
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("验证数据失败.融担主体编码不能为空");
                return dataResultVO;
            }


            if(PrjPrdPaySchMConstant.PAYER_STS_CD_PAID.equals(payerStsCd)){
                if(StringUtils.isEmpty(redmPaymentAccountNum)){
                    BaseLogUtils.newLogger("验证数据失败.我司赎回付款账户为空").setKeys("verifyRedmDataParam","redmPaymentAccountNum="+redmPaymentAccountNum,CurrentThreadContext.getCurrentUserName()).info();
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo("验证数据失败.请维护我司赎回付款账户");
                    return dataResultVO;
                }

                if(StringUtils.isEmpty(redmPayeeAccountNum)){
                    BaseLogUtils.newLogger("验证数据失败.资方赎回收款账户为空").setKeys("verifyRedmDataParam","redmPayeeAccountNum="+redmPayeeAccountNum,CurrentThreadContext.getCurrentUserName()).info();
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo("验证数据失败.请维护资方赎回收款账户");
                    return dataResultVO;
                }
                if("1".equals(offlineSettle)){
                    /**
                     * 已经线下赎回 线下赎回时间不能为空
                     */
                    if(StringUtils.isEmpty(insRedmTm)){
                        BaseLogUtils.newLogger("验证数据失败.线下赎回时间不能为空").setKeys("verifyRedmDataParam","insRedmTm="+insRedmTm,CurrentThreadContext.getCurrentUserName()).info();
                        dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                        dataResultVO.setInfo("验证数据失败.线下赎回时间不能为空");
                        return dataResultVO;
                    }

                    /**
                     * 已经线下赎回 赎回本金不能为空
                     */
                    if(StringUtils.isEmpty(redmPrinAmt)){
                        BaseLogUtils.newLogger("验证数据失败.赎回本金为空").setKeys("verifyRedmDataParam","redmPrinAmt="+redmPrinAmt,CurrentThreadContext.getCurrentUserName()).info();
                        dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                        dataResultVO.setInfo("验证数据失败.赎回本金不能为空");
                        return dataResultVO;
                    }

                    /**
                     * 已经线下赎回 赎回利息不能为空
                     */
                    if(StringUtils.isEmpty(redmIntAmt)){
                        BaseLogUtils.newLogger("验证数据失败.赎回利息为空").setKeys("verifyRedmDataParam","redmIntAmt="+redmIntAmt,CurrentThreadContext.getCurrentUserName()).info();
                        dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                        dataResultVO.setInfo("验证数据失败.赎回利息不能为空");
                        return dataResultVO;
                    }
                }

            }

            /**
             * 赎回本金
             */
            if(StringUtils.isNotBlank(redmPrinAmt)){
                entity.setRedmPrinAmt(DecimalUtils.convertYuanToFen(Double.valueOf(redmPrinAmt)).doubleValue());
            }
            /**
             * 赎回利息
             */
            if(StringUtils.isNotBlank(redmIntAmt)){
                entity.setRedmIntAmt(DecimalUtils.convertYuanToFen(Double.valueOf(redmIntAmt)).doubleValue());
            }
            /**
             * 赎回罚息
             */
            if(StringUtils.isNotBlank(redmPnlAmt)){
                entity.setRedmPnlAmt(DecimalUtils.convertYuanToFen(Double.valueOf(redmPnlAmt)).doubleValue());
            }
            /**
             * 赎回金额
             */
            if(StringUtils.isNotBlank(redmTotalAmt) && Double.valueOf(redmTotalAmt).longValue() != 0){
                entity.setRedmTotalAmt(DecimalUtils.convertYuanToFen(Double.valueOf(redmTotalAmt)).doubleValue());
            }else{
                if(null != entity.getRedmPrinAmt() && null != entity.getRedmIntAmt()){
                    entity.setRedmTotalAmt(DecimalUtils.add(entity.getRedmPrinAmt(),entity.getRedmIntAmt()));
                }
            }
            if("1".equals(offlineSettle)){
                /**
                 * 是否支持线下赎回
                 */
                int canOfflineRedm = prjInsRedmInterfaceInfoService.getPrjInsRedmConfig(entity.getInsCode(),PrjInsRedmInfoConstant.SYS_INS_CFG_INFO_C043);
                if(BaseConstant.IS_YESNO_NO == canOfflineRedm){
                    BaseLogUtils.newLogger("验证数据失败.机构不支持线下赎回,请重新选择").setKeys("verifyRedmDataParam","canOfflineRedm="+canOfflineRedm,CurrentThreadContext.getCurrentUserName()).info();
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo("验证数据失败.机构不支持线下赎回,请重新选择");
                    return dataResultVO;
                }
                entity.setInsRedmTm(DateUtils.formatStringToDate(insRedmTm, DateUtils.YYYY_MM_DD));
            }
            entity.setIsSubmitCreditRD(isSubmitCreditRD);
            entity.setSuretySubjectCode(suretySubjectCode);
            /**
             * 是否线下赎回
             */
            entity.setOfflineSettle(Integer.valueOf(offlineSettle));
        }else{
            /**
             * 客户经理需要校验的数据
             */
            if(StringUtils.isEmpty(insRedmReson)){
                BaseLogUtils.newLogger("验证数据失败.赎回原因为空").setKeys("verifyRedmDataParam","insRedmReson="+insRedmReson,CurrentThreadContext.getCurrentUserName()).info();
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("验证数据失败.赎回原因为空");
                return dataResultVO;
            }
            if(StringUtils.isEmpty(insRedmDetailReson)){
                BaseLogUtils.newLogger("验证数据失败.具体原因为空").setKeys("verifyRedmDataParam","insRedmDetailReson="+insRedmDetailReson,CurrentThreadContext.getCurrentUserName()).info();
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("验证数据失败.具体原因为空");
                return dataResultVO;
            }
        }

        /**
         * 查询所需数据
         */
        PrjInsRedmInfoQC qc = new PrjInsRedmInfoQC();
        qc.setPrjId(Long.valueOf(prjId));
        PrjInsRedmInfoVO redmApplyInfo = this.prjInsRedmInfoService.searchAssetsRedmApplyInfo(qc);
        BaseLogUtils.newLogger("查询资管赎回申请信息结束!").setKeys("verifyRedmDataParam","redmApplyInfo="+JSON.toJSONString(redmApplyInfo)).info();
        entity.setPrjId(redmApplyInfo.getPrjId());
        entity.setActLsAmt(redmApplyInfo.getActLsAmt());
        entity.setContAmt(redmApplyInfo.getContAmt());
        entity.setCstNm(redmApplyInfo.getCstNm());
        entity.setFundRasInsNm(redmApplyInfo.getFundRasInsNm());
        entity.setLsPd(redmApplyInfo.getLsPd());
        entity.setPaySchNo(redmApplyInfo.getPaySchNo());
        entity.setpNo(redmApplyInfo.getpNo());
        entity.setInsCode(redmApplyInfo.getInsCode());
        entity.setLsCntNo(redmApplyInfo.getLsCntNo());
        entity.setOvdAmt(redmApplyInfo.getOvdAmt());
        entity.setOvdDay(redmApplyInfo.getOvdDay());
        entity.setPnlAmt(redmApplyInfo.getPnlAmt());
        entity.setRelActAmt(redmApplyInfo.getRelActAmt());
        entity.setTotalActAmt(redmApplyInfo.getTotalActAmt());
        entity.setTotalRelRcptAmt(redmApplyInfo.getTotalRelRcptAmt());
        entity.setTotalIntRedmAft(redmApplyInfo.getTotalIntRedmAft());
        entity.setTotalIntRedmBef(redmApplyInfo.getTotalIntRedmBef());
        entity.setInsPayTime(redmApplyInfo.getInsPayTime());
        entity.setPaySchId(redmApplyInfo.getPaySchId());
        entity.setCstNm(redmApplyInfo.getCstNm());
        entity.setCstId(redmApplyInfo.getCstId());
        entity.setFundRasInsId(redmApplyInfo.getFundRasInsId());
        entity.setPayerStsCd(payerStsCd);
        entity.setIsOverdue(redmApplyInfo.getIsOverdue());
        /**
         * 签署重推签署状态：默认未重推
         */
        entity.setCntSigStatus(PrjInsRedmInfoConstant.Redm003CNT.REDM_003_0);
        /**
         * 资管赎回状态 : 赎回中
         */
        entity.setRedmStatus(PrjInsRedmInfoConstant.Redm002Staus.REDM_002_1);

        //查询资方支付表还款情况
        PrjPrdPaySchDQueryCondition condition = new PrjPrdPaySchDQueryCondition();
        condition.setFeeTypCd(CapitalConstant.CODE_FEE_TYP_CD_S01);
        condition.setPaySchId(entity.getPaySchId());
        condition.setArAmt(0L);
        List<PrjPrdPaySchDDTO> prjPrdPaySchDDTOS = prjPaySchDApiService.searchPaySchDtlByFeeTypCd(condition);
        PrjPrdPaySchDDTO prjPrdPaySchDDTO = null;
        if(CollectionUtils.isNotEmpty(prjPrdPaySchDDTOS)){
            prjPrdPaySchDDTO = prjPrdPaySchDDTOS.get(0);
        }else{
            BaseLogUtils.newLogger("验证数据失败.符合赎回条件的资方支付表数据不存在查询条件").setKeys("verifyRedmDataParam",JSON.toJSONString(condition),CurrentThreadContext.getCurrentUserName()).info();
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo("资方支付表已全部还款,无法赎回,请核查数据!");
            return dataResultVO;
        }

        /**
         * 赎回开始期次
         */
        entity.setRedmStPd(Long.valueOf(prjPrdPaySchDDTO.getPayPd()));
        /**
         * 赎回开始日期
         */
        entity.setRedmStDt(prjPrdPaySchDDTO.getPayDt());
        /**
         * 资管赎回类型 1.贷前（项目流程） 2.贷中（放款流程） 3.贷后（已赎回）4.线下OA 5.贷后(已转回)
         */
        if(null != redmApplyInfo.getInsPayTime()){
            /**
             * 资方放款 设置为贷后(已赎回)
             */
            entity.setRedmTypCd(PrjInsRedmInfoConstant.REDM_TYPE_3);
        }else{
            /**
             * 资方未放款 设置为贷后(已转回)
             */
            entity.setRedmTypCd(PrjInsRedmInfoConstant.REDM_TYPE_5);
        }


        /**
         * 是否结清
         */
        entity.setSettleStatus(PrjInsRedmInfoConstant.PRJ_INS_REDM_RESULT_UNCOMMIT);

        /**
         * 赎回原因
         */
        entity.setInsRedmResonCode(insRedmReson);
        /**
         * 具体原因
         */
        entity.setInsRedmDetailResonCode(insRedmDetailReson);
        /**
         *其他原因
         */
        entity.setOtherInsRedmReson(otherInsRedmReson);

        /**
         * 我司赎回付款账户账号
         */
        if(StringUtils.isNotEmpty(redmPaymentAccountNum)){
            entity.setRedmPaymentAccountNum(redmPaymentAccountNum);
        }
        /**
         * 资方赎回收款账户账号
         */
        if(StringUtils.isNotEmpty(redmPayeeAccountNum)){
            entity.setRedmPayeeAccountNum(redmPayeeAccountNum);
        }

        /**
         * 转账附言
         */
        entity.setPaymentReason(paymentReason);
        BaseLogUtils.newLogger("资管资产赎回,添加封装数据结束").setKeys("add","entity="+ JSON.toJSONString(entity)).info();
        return dataResultVO;
    }

    /**
     * 查询来款核销信息
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initVfInfo.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initVfInfo(HttpServletRequest request) {
        String paySchId = request.getParameter("paySchId");
        try {
            if (StringUtils.isEmpty(paySchId)) {
                throw new BaseException("支付表id不能为空");
            }
            List<CapFundVO> list = this.prjInsRedmInfoService.searchVfInfo4InsRedeem(Long.valueOf(paySchId));
            ListPageVO<CapFundVO> listPage = new ListPageVO<CapFundVO>(list, list.size());
            return listPage;
        } catch (BaseException ex) {
            BaseLogUtils.newLogger("查询来款核销信息").setLogOperType(LogOperEnum.REQ).setKeys("initVfInfo", paySchId, CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0001);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.newLogger("查询来款核销信息").setLogOperType(LogOperEnum.REQ).setKeys("initVfInfo", paySchId, CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0099);
            throw ex;
        }

    }

    /**
     * 查询资管资产赎回申请信息
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initPrjDtlInfo.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initPrjDtlInfo(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        BaseLogUtils.newLogger("初始化项目产品明细").setLogOperType(LogOperEnum.REQ).setKeys("initPrjDtlInfo",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        String prjId = request.getParameter("prjId");
        ListPageVO<PrjDtlInsRedmInfoVO> listPage = null;
        PrjInsRedmInfoQC qc = new PrjInsRedmInfoQC();
        try {
            if (StringUtils.isEmpty(prjId)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_PARAM_IS_BAD);
                BaseLogUtils.newLogger("请求参数项目prjId不能为空").setLogOperType(LogOperEnum.REQ).setKeys("initPrjDtlInfo",prjId,CurrentThreadContext.getCurrentUserName()).info();
                return result;
            }
            qc.setPrjId(Long.valueOf(prjId));
            List<PrjDtlInsRedmInfoVO> voList = this.prjInsRedmInfoService.selectPrjDtlInfo(qc);
            if (null == voList) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.newLogger("获取数据,数据不存在").setLogOperType(LogOperEnum.REQ).setKeys("initPrjDtlInfo",prjId,CurrentThreadContext.getCurrentUserName()).info();
            }
            listPage = new ListPageVO<PrjDtlInsRedmInfoVO>(voList, voList.size());
            result.setData(voList);
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("获取失败").setLogOperType(LogOperEnum.REQ).setKeys("initPrjDtlInfo",prjId,CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0001);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("获取失败").setLogOperType(LogOperEnum.REQ).setKeys("initPrjDtlInfo",prjId,CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return listPage;
    }

    /**
     *获取赎回原因
     */
    @RequestMapping(value = "/getInsRedmReson.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object getInsRedmReson(HttpServletRequest request,HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取数据成功");
        /**
         * 是否赎回原因
         */
        String isPcode = request.getParameter("isPcode");
        /**
         * 赎回具体原因对应的父CODE
         */
        String pCode = request.getParameter("pCode");
        /**
         * 数据字典code
         */
        String sysCode = request.getParameter("sysCode");
        try {
             if(StringUtils.isNotEmpty(isPcode) && "1".equals(isPcode)) {
                 /**
                  * 赎回原因
                  */
                 List<KeyValueVO> insRedmResonCodeList = this.sysDictionaryApiService.getKvList(PrjInsRedmInfoConstant.SYS_DIS_CODE_REDM_008, CapitalConstant.SYSCD, CapitalConstant.SYSORG);
                 if (CollectionUtils.isEmpty(insRedmResonCodeList)) {
                     result.setSuccess(BaseConstant.IS_YESNO_NO);
                     result.setInfo("数据不存在！");
                     BaseLogUtils.newLogger("获取赎回原因").setKeys("getInsRedmReson", "insRedmResonCodeList=" + JSON.toJSONString(insRedmResonCodeList), CurrentThreadContext.getCurrentUserName()).info();
                 }
                 JSONArray insRedmResonCodeListJson = JSONArray.fromObject(insRedmResonCodeList.toArray());
                 result.setData(insRedmResonCodeListJson);
                 result.setData(insRedmResonCodeList);
             }else if(StringUtils.isNotEmpty(isPcode) && "0".equals(isPcode)){
                 /**
                  * 具体原因
                  */
                 List<SysDictionaryDTO> insRedmDetailResonCodeList = this.sysDictionaryApiService.searchChild(CapitalConstant.SYSCD, CapitalConstant.SYSORG, PrjInsRedmInfoConstant.SYS_DIS_CODE_REDM_009, pCode);
                 if(CollectionUtils.isEmpty(insRedmDetailResonCodeList)){
                     result.setSuccess(BaseConstant.IS_YESNO_NO);
                     result.setInfo("数据不存在！");
                     BaseLogUtils.newLogger("获取赎回具体原因").setKeys("getInsRedmReson","insRedmDetailResonCodeList="+JSON.toJSONString(insRedmDetailResonCodeList),CurrentThreadContext.getCurrentUserName()).info();
                 }else{
                     List<KeyValueVO> kvList = new ArrayList<>();
                     if(CollectionUtils.isNotEmpty(insRedmDetailResonCodeList)){
                         for (SysDictionaryDTO sysDictionaryDTO : insRedmDetailResonCodeList) {
                             KeyValueVO keyValueVO = new KeyValueVO();
                             keyValueVO.setKey(sysDictionaryDTO.getCode());
                             keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
                             kvList.add(keyValueVO);
                         }
                     }
                     JSONArray insRedmDetailResonCodeListJson = JSONArray.fromObject(kvList.toArray());
                     result.setData(insRedmDetailResonCodeListJson);
                 }
             }else{
                 result.setSuccess(BaseConstant.IS_YESNO_NO);
                 result.setInfo("数据异常");
             }
        }catch(BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("获取赎回原因").setLogOperType(LogOperEnum.REQ).setKeys("getInsRedmReson", CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0099);
        }catch(Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("获取赎回原因").setLogOperType(LogOperEnum.REQ).setKeys("getInsRedmReson", CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;
    }

}

